var t, a, e = getApp(), n = require("../../../utils/util.js");

Page({
    data: {
        isShow: !1,
        keyBoardType: 1,
        numList: [],
        numListLength: 0,
        originalPrice: "",
        presentPrice: "",
        sellNum: "",
        bizId: "",
        unavailableBiz: "",
        cardTitle: "",
        style: "position:fixed;width:100%;height:667",
        unable: []
    },
    onLoad: function(e) {
        (t = this).setData({
            shopId: e.shopId
        }), a = [], t.getCardInfo(), t.getUnableShop(), wx.getSystemInfo({
            success: function(a) {
                t.setData({
                    screenHeight: a.screenHeight,
                    style: "width:100%;height:100%;"
                });
            }
        });
    },
    onReady: function() {},
    call: function() {
        wx.makePhoneCall({
            phoneNumber: "4006046606"
        });
    },
    message: function() {
        var a = "";
        t.data.unable.forEach(function(t) {
            return a = t + "\r\n" + a;
        }), wx.showModal({
            title: "以下门店不可使用年卡",
            showCancel: !1,
            content: a,
            success: function(t) {}
        });
    },
    inputOk: function(a) {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
        var e = t.data.screenHeight;
        if (t.setData({
            isShow: !1,
            style: "position:fixed;width:100%;height:" + [ e ] + ";"
        }), 7 == t.data.numListLength) {
            var n = t.data.numList[0] + t.data.numList[1] + t.data.numList[2] + t.data.numList[3] + t.data.numList[4] + t.data.numList[5] + t.data.numList[6];
            t.setData({
                chepai: n
            });
        } else wx.showToast({
            title: "请完善车牌再确认",
            icon: "warn"
        });
    },
    inputdelete: function(a) {
        t.data.numList;
        var e = [];
        t.setData({
            numList: e
        });
    },
    inputChange: function(a) {
        var e = t.data.numList;
        null != a.detail && void 0 !== a.detail && (e.push(a.detail), t.setData({
            numList: e,
            numListLength: e.length
        }), t.data.numList.length >= 1 && t.setData({
            keyBoardType: 2,
            isShow: !0
        }));
    },
    changePanel: function() {
        t.setData({
            keyBoardType: 1,
            isShow: !0
        }), wx.pageScrollTo({
            scrollTop: 200,
            duration: 300
        });
    },
    changePanel1: function() {
        t.setData({
            keyBoardType: 2,
            isShow: !0
        }), wx.pageScrollTo({
            scrollTop: 200,
            duration: 300
        });
    },
    closePanel: function() {
        t.setData({
            isShow: !1
        }), wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
    },
    getUnableShop: function() {
        var a = e.globalData.token, o = "", i = [];
        n.request(e, "wx/biz/getCardCanNotUse", "GET", {
            token: a
        }, function(a) {
            var e = a.data;
            a.state && (e.length > 0 && e.forEach(function(t) {
                o = t.cityName + ":" + t.shopName, i.push(o);
            }), t.setData({
                unable: i
            }));
        }, function(t) {});
    },
    getCardInfo: function() {
        var a = e.globalData.token;
        n.request(e, "wx/biz/getWxBizCard", "GET", {
            token: a,
            shopId: t.data.shopId
        }, function(a) {
            a.state && (t.setData({
                originalPrice: n.convertMath(a.data[0].originalPrice),
                presentPrice: n.convertMath(a.data[0].presentPrice),
                sellNum: a.data[0].sellNum,
                bizId: a.data[0].bizId,
                cardTitle: a.data[0].cardTitle,
                carNo: a.data[0].carNo
            }), null != a.data[0].carNo && "" != a.data[0].carNo && t.setData({
                numList: a.data[0].carNo,
                numListLength: a.data[0].carNo.length
            }));
        }, function(t) {});
    },
    goBuy: function() {
        var a = e.globalData.token;
        if (7 == t.data.numListLength) {
            var o = t.data.numList[0] + t.data.numList[1] + t.data.numList[2] + t.data.numList[3] + t.data.numList[4] + t.data.numList[5] + t.data.numList[6];
            t.setData({
                chepai: o
            }), t.data.sellNum > 0 && wx.showModal({
                title: "请确认",
                content: "您绑定的车牌:" + t.data.chepai,
                success: function(o) {
                    o.confirm ? n.request(e, "wx/cust/insertAutoWashCard", "POST", {
                        token: a,
                        shopId: t.data.shopId,
                        carNo: t.data.chepai
                    }, function(o) {
                        o.state && (t.setData({
                            serviceOrderId: o.data.serviceOrderId
                        }), wx.request({
                            url: e.globalData.url + "wx/pay/info",
                            data: n.json2Form({
                                token: a,
                                orderId: o.data.serviceOrderId,
                                couponId: "",
                                payType: 2
                            }),
                            header: {
                                "Content-Type": "application/x-www-form-urlencoded"
                            },
                            method: "POST",
                            success: function(o) {
                                if (o.data.state) {
                                    var i = o.data.data;
                                    wx.requestPayment({
                                        timeStamp: i.timeStamp,
                                        nonceStr: i.nonceStr,
                                        package: i.packageValue,
                                        signType: i.signType,
                                        paySign: i.paySign,
                                        success: function(o) {
                                            n.request(e, "wx/cust/autoWashCardIntoCardBag", "GET", {
                                                token: a,
                                                shopId: t.data.shopId,
                                                carNo: t.data.chepai
                                            }, function(a) {
                                                a.state && (setTimeout(function() {
                                                    wx.redirectTo({
                                                        url: "/pages/autoWash/prepare3/index?shopId=" + t.data.shopId
                                                    });
                                                }, 1e3), wx.showToast({
                                                    title: "购买成功"
                                                }));
                                            }, function(t) {});
                                        },
                                        fail: function(t) {
                                            "requestPayment:fail cancel" == t.errMsg && wx.request({
                                                url: e.globalData.url + "wx/pay/cancel",
                                                data: n.json2Form({
                                                    token: a,
                                                    payId: i.payId
                                                }),
                                                header: {
                                                    "Content-Type": "application/x-www-form-urlencoded"
                                                },
                                                method: "POST",
                                                success: function(t) {},
                                                fail: function(t) {}
                                            });
                                        }
                                    });
                                } else wx.showToast({
                                    title: "发起支付失败:" + o.data.message
                                });
                            }
                        }));
                    }, function(t) {}) : o.cancel && wx.showToast({
                        title: "取消成功"
                    });
                }
            });
        } else wx.showToast({
            title: "请完善车牌再确认",
            icon: "warn"
        });
    }
});